var pageii = null;
var grid = null;
$(function() {

	grid = lyGrid({
		pagId : 'paging',
		l_column : [{
			colkey : "clientname",
			name : "客户名称"
		}, {
			colkey : "Name",
			name : "名称"
		}, {
			colkey : "mold_encode",
			name : "模具编码"
		}, {
			colkey : "number",
			name : "订单数量"
		},{
			colkey : "client_weight",
			name : "客户定重"
		},{
			colkey : "production_weight",
			name : "排产重量"
		}, {
			colkey : "receiving_date",
			name : "接单日期",
			renderData : function(rowindex,data, rowdata, column) {
					return new Date(data).format("yyyy-MM-dd hh:mm:ss");
			}
		},{
			colkey : "production_date",
			name : "排单日期",
			renderData : function(rowindex,data, rowdata, column) {
				if(data!=''&&data!=null){
					return new Date(data).format("yyyy-MM-dd hh:mm:ss");
				}else{
					return '暂未排';
				}
			}
		}, {
			colkey : "po_no",
			name : "采购订单号"
		}, {
			colkey : "client_encode",
			name : "客户编码"
		}, {
			colkey : "shipping_time",
			name : "出货时间",
			renderData : function(rowindex,data, rowdata, column) {
				return new Date(data).format("yyyy-MM-dd hh:mm:ss");
			}
		},{
			colkey : "pricing_method",
			name : "定价方式"
		},{
		    colkey : "job_number",
			name : "作业号"
		},{
			colkey : "price",
			name : "单价"
		},{
			colkey : "salesman",
			name : "业务员"
		},{
			colkey : "planner",
			name : "计划员"
		},{
			colkey : "byuser",
			name : "创建人"
		},{
			colkey : "finish_time",
			name : "订单完成时间",
			renderData : function(rowindex,data, rowdata, column) {
				if(data!=''&&data!=null){
					return new Date(data).format("yyyy-MM-dd hh:mm:ss");
				}else{
					return '';
				}
			}
		}],
		jsonUrl : rootPath + '/order/order_findByPage.shtml',
		dymCol:true,
		checkbox : true,
		serNumber : false
	});
	$("#addOrder").click("click", function() {
		addAccount();
	});
	$("#editOrder").click("click", function() {
		editAccount();
	});
	$("#delOrder").click("click", function() {
		delAccount();
	});
	$("#orderplanner").click("click", function() {
		orderplannerAccount();
	});
	$("#OrderChai").click("click",function(){
		OrderChaiAccount();
	});
	$("#Orderinfo").click("click",function(){
		OrderchaiinfoAccount();
	});
	$("#search").click("click", function() {// 绑定查询按扭
		
		var searchParams = $("#searchForm").serializeJson();
		grid.setOptions({
			data : searchParams
		});
	});
	
});
function editAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1) {
		layer.msg("只能选中一个");
		return;
	}
	if(cbox == ""){
		layer.msg("需要选择一个");
		return;
	}
	pageii = layer.open({
		title : "编辑订单",
		type : 2,
		area : [ "800px", "100%" ],
		content : rootPath + '/order/order_edit.shtml?id=' + cbox
	});
}
function addAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1 ) {
		layer.msg("只能选中一个");
		return;
	}
	if(cbox == ""){
		layer.msg("需要选择一个");
		return;
	}
	pageii = layer.open({
		title : "新增订单",
		type : 2,
		area : [ "800px", "100%" ],
		content : rootPath + '/order/order_add.shtml?id=' + cbox
	});
}
function delAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择删除项！！");
		return;
	}
	layer.confirm('是否删除？', function(index) {
		var url = rootPath + '/order/order_deleteEntity.shtml';
		var s = CommnUtil.ajax(url, {
			ids : cbox.join(",")
		}, "json");
		if (s == "success") {
			layer.msg('删除成功');
			grid.loadData();
		} else {
			layer.msg('删除失败');
		}
	});
}
function orderplannerAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1 ) {
		layer.msg("只能选中一个");
		return;
	}
	if(cbox == ""){
		layer.msg("需要选择一个");
		return;
	}
	pageii = layer.open({
		title : "叫料计划",
		type : 2,
		area : [ "800px", "100%" ],
		content : rootPath + '/order/order_planner.shtml?id=' + cbox
	});
}
function OrderChaiAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1 ) {
		layer.msg("只能选中一个");
		return;
	}
	if(cbox == ""){
		layer.msg("需要选择一个");
		return;
	}
	pageii = layer.open({
		title : "订单拆分",
		type : 2,
		area : [ "800px", "100%" ],
		content : rootPath + '/order/order_chai.shtml?id=' + cbox
	});
}
function OrderchaiinfoAccount(){
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1 ) {
		layer.msg("只能选中一个");
		return;
	}
	if(cbox == ""){
		layer.msg("需要选择一个");
		return;
	}
	pageii = layer.open({
		title : "订单拆分情况",
		type : 2,
		area : [ "800px", "100%" ],
		content : rootPath + '/order/order_chaiinfo.shtml?id=' + cbox
	});
}